/*
 * AbstractButtonDelegate.h  0.4.0 / Dec 04, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#ifndef ABSTRACTBUTTONDELEGATE_H
#define ABSTRACTBUTTONDELEGATE_H

#include "Cute4jSwing.h"

#include "ComponentDelegate.h"
#include "QIconAdapter.h"

// AbstractButtonDelegate Class. -----------------------------------------------

/*!
 * \brief AbstractButton Delegate.
 *
 * \author Slobodan Vrkacevic
 * \version 0.4.0
 */
class CUTE4J_EXPORT AbstractButtonDelegate : public ComponentDelegate
{
  Q_OBJECT
protected:
  AbstractButtonDelegate(JNIEnv *env, jobject obj, QAbstractButton *button);
  AbstractButtonDelegate(JNIEnv *env, jobject obj);
public slots: // native calls
  void setPressed(JNIEnv *env, jboolean pressed);
  void setText(JNIEnv *env, jstring text);
  void setIcon(JNIEnv *env, jobject iconSet);
  void setIconSize(JNIEnv *env, jint width, jint height);
public: // native calls
  static void initialize(JNIEnv *env, jclass cls);
  static jlong newInstance(JNIEnv *env, jobject obj);
public: // native callbacks
  jboolean buttonPressed();
  jboolean buttonReleased();
  void buttonClicked(jint modifiers);
public:
  inline QAbstractButton *qAbstractButton() const;
public:
  virtual jobject getBackground(JNIEnv *env, jclass colorClass);
  virtual void setBackground(JNIEnv *env, jint argb);
  virtual void setNullBackground(JNIEnv *env);
  virtual jobject getForeground(JNIEnv *env, jclass colorClass);
  virtual void setForeground(JNIEnv *env, jint argb);
  virtual void setNullForeground(JNIEnv *env);
protected slots:
  void pressedSlot();
  void releasedSlot();
  void clickedSlot();
protected:
  inline void setIconType(QIconAdapter::IconType iconType);
protected:
  virtual bool filterKeyPressedEvent(QObject *obj, QKeyEvent *e);
  virtual bool filterKeyReleasedEvent(QObject *obj, QKeyEvent *e);
  virtual bool filterMouseEnterEvent(QObject *obj, QMouseEvent *e);
  virtual bool filterMouseLeaveEvent(QObject *obj, QMouseEvent *e);
private:
  Qt::KeyboardModifiers m_modifiers;
  QIconAdapter::IconType m_iconType;
private:
  static jmethodID sm_buttonPressedMID;
  static jmethodID sm_buttonReleasedMID;
  static jmethodID sm_buttonClickedMID;
};

// AbstractButtonDelegate :: Public Inline Member Function. --------------------

/*!
 * \brief Returns QAbstractButton adaptee.
 *
 * \return QAbstractButton adaptee
 */
inline QAbstractButton *AbstractButtonDelegate::qAbstractButton() const
{
  return static_cast<QAbstractButton *>(qObject());
}

// AbstractButtonDelegate :: Protected Inline Member Function. -----------------

/*!
 * \brief Sets current icon type.
 *
 * \param iconType the icon type
 */
inline void AbstractButtonDelegate::setIconType(QIconAdapter::IconType iconType)
{
  m_iconType = iconType;
}

// Macro Definition. -----------------------------------------------------------

#define ABSTRACT_BUTTON_DELEGATE \
    (reinterpret_cast<AbstractButtonDelegate *>(delegate))

#endif // ABSTRACTBUTTONDELEGATE_H
